package com.qianyu.project.core.api;

import com.qianyu.project.core.service.IFlowService;
import com.qianyu.project.utils.Result;
import com.qianyu.project.utils.ResultTool;
import com.qianyu.project.vo.FlowVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * @Author mfy
 * @desc
 */
@RestController
@RequestMapping("flows")
public class FlowController {

    @Autowired
    private IFlowService iFlowService;

    @GetMapping("")
    public Result list(@RequestParam Map<String,String> param ){
        return ResultTool.success(iFlowService.list(param));
    }

    @PostMapping("")
    public Result save(@RequestBody FlowVo flowVo){
        iFlowService.save(flowVo);
        return ResultTool.success();
    }

    @GetMapping("/getOneByFlowName/{flowName}")
    public Result getOneByFlowName(@PathVariable String flowName){
        return ResultTool.success(iFlowService.getByName(flowName));
    }

    @DeleteMapping("{flowId}")
    public Result del(@PathVariable Integer flowId){
        iFlowService.del(flowId);
        return ResultTool.success();
    }

    @GetMapping("{ids}")
    public Result getOne(@PathVariable Integer ids){
        return ResultTool.success(iFlowService.getById(ids));
    }

}
